﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SR = System.Reflection;

namespace AL.Doodled.Extensions.MemberInfo
{
    /// <summary>
    /// This class only contains extension methods for the MemberInfo class.
    /// </summary>
    public static class MemberInfoExtensionMethods
    {
        /// <summary>
        /// Takes a MemberInfo instance and try to get it's value
        /// as a non-indexed property and a field.
        /// </summary>
        /// <returns>The value or null if unsuccessfull.</returns>
        public static object GetValue(this SR.MemberInfo mi, object obj)
        {
            if (mi is SR.PropertyInfo)
                return ((SR.PropertyInfo)mi).GetValue(obj, null);
            else if (mi is SR.FieldInfo)
                return ((SR.FieldInfo)mi).GetValue(obj);
            else
                return null;
        }
    }
}
